load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "executors",
    deps = [
        ":async",  # @manual
        ":cpu_thread_pool_executor",  # @manual
        ":fiber_io_executor",  # @manual
        ":future_executor",  # @manual
        ":global_executor",  # @manual
        ":io_executor",  # @manual
        ":io_object_cache",  # @manual
        ":io_thread_pool_executor",  # @manual
        ":serial_executor",  # @manual
        ":thread_pool_executor",  # @manual
        ":threaded_executor",  # @manual
        "//folly/executors/task_queue:blocking_queue",  # @manual
        "//folly/executors/task_queue:lifo_sem_mpmc_queue",  # @manual
        "//folly/executors/task_queue:priority_lifo_sem_mpmc_queue",  # @manual
        "//folly/executors/task_queue:unbounded_blocking_queue",  # @manual
        "//folly/executors/thread_factory",  # @manual
        "//folly/executors/thread_factory:named_thread_factory",  # @manual
        "//folly/executors/thread_factory:priority_thread_factory",  # @manual
    ],
)

cpp_library(
    name = "async",
    hdrs = ["Async.h"],
    deps = [
        ":global_executor",
        "//folly/futures:core",
    ],
)

cpp_library(
    name = "codel",
    srcs = ["Codel.cpp"],
    hdrs = ["Codel.h"],
    deps = [
        "//folly/portability:gflags",
    ],
)

cpp_library(
    name = "cpu_thread_pool_executor",
    srcs = ["CPUThreadPoolExecutor.cpp"],
    hdrs = ["CPUThreadPoolExecutor.h"],
    deps = [
        ":queue_observer",
        ":thread_pool_executor",
        "//folly:executor",
        "//folly:memory",
        "//folly:optional",
        "//folly/executors/task_queue:priority_lifo_sem_mpmc_queue",
        "//folly/executors/task_queue:priority_unbounded_blocking_queue",
        "//folly/executors/task_queue:unbounded_blocking_queue",
        "//folly/portability:gflags",
        "//folly/synchronization:throttled_lifo_sem",
    ],
)

cpp_library(
    name = "drivable_executor",
    hdrs = ["DrivableExecutor.h"],
    deps = [
        "//folly:executor",
    ],
)

cpp_library(
    name = "edf_thread_pool_executor",
    srcs = ["EDFThreadPoolExecutor.cpp"],
    hdrs = ["EDFThreadPoolExecutor.h"],
    deps = [
        ":soft_real_time_executor",
        ":thread_pool_executor",
        "//folly:scope_guard",
        "//folly/concurrency:process_local_unique_id",
        "//folly/portability:gflags",
        "//folly/synchronization:lifo_sem",
        "//folly/synchronization:throttled_lifo_sem",
        "//folly/tracing:static_tracepoint",
        "@glog",
    ],
)

cpp_library(
    name = "fiber_io_executor",
    hdrs = ["FiberIOExecutor.h"],
    deps = [
        ":io_executor",
        "//folly/fibers:fiber_manager_map",
    ],
)

cpp_library(
    name = "future_executor",
    hdrs = ["FutureExecutor.h"],
    deps = [
        "//folly/functional:invoke",
        "//folly/futures:core",
    ],
)

cpp_library(
    name = "global_executor",
    srcs = ["GlobalExecutor.cpp"],
    hdrs = ["GlobalExecutor.h"],
    deps = [
        ":cpu_thread_pool_executor",
        ":inline_executor",
        ":io_executor",
        ":io_thread_pool_executor",
        "//folly:executor",
        "//folly:function",
        "//folly:shared_mutex",
        "//folly:singleton",
        "//folly/detail:async_trace",
        "//folly/portability:gflags",
        "//folly/system:hardware_concurrency",
    ],
)

cpp_library(
    name = "global_thread_pool_list",
    srcs = ["GlobalThreadPoolList.cpp"],
    hdrs = ["GlobalThreadPoolList.h"],
    deps = [
        "//folly:cpp_attributes",
        "//folly:indestructible",
        "//folly:synchronized",
        "//folly:thread_local",
        "//folly/system:thread_id",
    ],
)

cpp_library(
    name = "inline_executor",
    srcs = ["InlineExecutor.cpp"],
    hdrs = ["InlineExecutor.h"],
    deps = [
        "//folly:c_portability",
        "//folly:cpp_attributes",
        "//folly:executor",
        "//folly:indestructible",
    ],
)

cpp_library(
    name = "manual_executor",
    srcs = ["ManualExecutor.cpp"],
    hdrs = ["ManualExecutor.h"],
    deps = [
        "//folly/executors:drivable_executor",
        "//folly/executors:scheduled_executor",
        "//folly/executors:sequenced_executor",
        "//folly/synchronization:lifo_sem",
    ],
)

cpp_library(
    name = "io_executor",
    hdrs = ["IOExecutor.h"],
    deps = [
        "//folly:executor",
    ],
)

cpp_library(
    name = "io_object_cache",
    hdrs = ["IOObjectCache.h"],
    deps = [
        ":global_executor",
        "//folly:thread_local",
        "//folly/io/async:async_base",
    ],
)

cpp_library(
    name = "io_thread_pool_executor",
    srcs = ["IOThreadPoolExecutor.cpp"],
    hdrs = ["IOThreadPoolExecutor.h"],
    deps = [
        ":io_executor",
        ":queue_observer",
        ":thread_pool_executor",
        "//folly:portability",
        "//folly/detail:memory_idler",
        "//folly/io/async:event_base_manager",
        "//folly/portability:gflags",
        "//folly/synchronization:relaxed_atomic",
        "@glog",
    ],
)

cpp_library(
    name = "soft_real_time_executor",
    srcs = ["SoftRealTimeExecutor.cpp"],
    hdrs = ["SoftRealTimeExecutor.h"],
    deps = [
        "//folly:executor",
        "@glog",
    ],
)

cpp_library(
    name = "scheduled_executor",
    hdrs = ["ScheduledExecutor.h"],
    deps = [
        "//folly:executor",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "serial_executor",
    hdrs = [
        "SerialExecutor.h",
        "SerialExecutor-inl.h",
    ],
    deps = [
        ":global_executor",
        ":serialized_executor",
        "//folly:exception_string",
        "//folly:scope_guard",
        "//folly/concurrency:unbounded_queue",
        "//folly/io/async:request_context",
        "//folly/synchronization:distributed_mutex",
        "//folly/synchronization:relaxed_atomic",
        "@glog",
    ],
)

cpp_library(
    name = "sequenced_executor",
    hdrs = ["SequencedExecutor.h"],
    deps = [
        "//folly:executor",
    ],
)

cpp_library(
    name = "serialized_executor",
    hdrs = ["SerializedExecutor.h"],
    deps = [
        ":sequenced_executor",
    ],
)

cpp_library(
    name = "strand_executor",
    srcs = ["StrandExecutor.cpp"],
    hdrs = ["StrandExecutor.h"],
    deps = [
        ":global_executor",
        ":serialized_executor",
        "//folly:exception_string",
        "//folly:optional",
        "//folly/concurrency:unbounded_queue",
        "//folly/io/async:request_context",
        "@glog",
    ],
)

cpp_library(
    name = "thread_pool_executor",
    srcs = ["ThreadPoolExecutor.cpp"],
    hdrs = ["ThreadPoolExecutor.h"],
    deps = [
        ":global_thread_pool_list",
        "//folly:default_keep_alive_executor",
        "//folly:memory",
        "//folly:shared_mutex",
        "//folly/concurrency:process_local_unique_id",
        "//folly/executors/task_queue:lifo_sem_mpmc_queue",
        "//folly/executors/thread_factory:named_thread_factory",
        "//folly/io/async:request_context",
        "//folly/portability:gflags",
        "//folly/portability:pthread",
        "//folly/synchronization:asymmetric_thread_fence",
        "//folly/synchronization:atomic_struct",
        "//folly/synchronization:baton",
        "//folly/tracing:static_tracepoint",
        "@glog",
    ],
)

cpp_library(
    name = "threaded_executor",
    srcs = ["ThreadedExecutor.cpp"],
    hdrs = ["ThreadedExecutor.h"],
    deps = [
        "//folly:executor",
        "//folly:scope_guard",
        "//folly/concurrency:unbounded_queue",
        "//folly/container:f14_hash",
        "//folly/executors/thread_factory",
        "//folly/executors/thread_factory:named_thread_factory",
        "//folly/system:thread_name",
        "@glog",
    ],
)

cpp_library(
    name = "timed_drivable_executor",
    srcs = ["TimedDrivableExecutor.cpp"],
    hdrs = ["TimedDrivableExecutor.h"],
    deps = [
        ":drivable_executor",
        "//folly/concurrency:unbounded_queue",
    ],
)

cpp_library(
    name = "timekeeper_scheduled_executor",
    srcs = ["TimekeeperScheduledExecutor.cpp"],
    hdrs = ["TimekeeperScheduledExecutor.h"],
    deps = [
        ":scheduled_executor",
        "//folly/futures:core",
        "@glog",
    ],
)

cpp_library(
    name = "queued_immediate_executor",
    srcs = ["QueuedImmediateExecutor.cpp"],
    hdrs = ["QueuedImmediateExecutor.h"],
    deps = [
        ":inline_executor",
        "//folly:executor",
        "//folly:indestructible",
        "//folly:scope_guard",
        "//folly:thread_local",
        "//folly/io/async:request_context",
    ],
)

cpp_library(
    name = "executor_with_priority",
    srcs = ["ExecutorWithPriority.cpp"],
    hdrs = [
        "ExecutorWithPriority.h",
        "ExecutorWithPriority-inl.h",
    ],
    deps = [
        "//folly:executor",
        "@glog",
    ],
)

cpp_library(
    name = "metered_executor",
    hdrs = [
        "MeteredExecutor.h",
        "MeteredExecutor-inl.h",
    ],
    deps = [
        ":queue_observer",
        "//folly:default_keep_alive_executor",
        "//folly/concurrency:unbounded_queue",
        "//folly/io/async:async_base",
    ],
)

cpp_library(
    name = "io_thread_pool_deadlock_detector_observer",
    srcs = ["IOThreadPoolDeadlockDetectorObserver.cpp"],
    hdrs = ["IOThreadPoolDeadlockDetectorObserver.h"],
    deps = [
        "//folly:singleton",
        "//folly/concurrency:deadlock_detector",
        "//folly/executors:io_thread_pool_executor",
        "//folly/executors:thread_pool_executor",
    ],
)

cpp_library(
    name = "queue_observer",
    srcs = ["QueueObserver.cpp"],
    hdrs = [
        "QueueObserver.h",
    ],
    deps = [
        "//folly:function",
        "//folly:portability",
        "//folly:synchronized",
        "//folly/portability:sys_types",
    ],
)

cpp_library(
    name = "virtual_executor",
    hdrs = [
        "VirtualExecutor.h",
    ],
    deps = [
        "//folly:default_keep_alive_executor",
    ],
)

cpp_library(
    name = "function_scheduler",
    srcs = ["FunctionScheduler.cpp"],
    hdrs = ["FunctionScheduler.h"],
    deps = [
        "//folly:conv",
        "//folly:function",
        "//folly:random",
        "//folly:range",
        "//folly:string",
        "//folly/container:f14_hash",
        "//folly/hash",
        "//folly/system:thread_name",
        "@glog",
    ],
)

cpp_library(
    name = "threaded_repeating_function_runner",
    srcs = ["ThreadedRepeatingFunctionRunner.cpp"],
    hdrs = ["ThreadedRepeatingFunctionRunner.h"],
    deps = [
        "//folly:function",
        "//folly/system:thread_name",
        "@glog",
    ],
)

cpp_library(
    name = "execution_observer",
    srcs = ["ExecutionObserver.cpp"],
    hdrs = ["ExecutionObserver.h"],
    deps = [
        "//folly/tracing:static_tracepoint",
        "@boost.intrusive",
    ],
)
